<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>盘点任务管理</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/logic/checkTask";
        var basic_WUrl="logic/checkTask";
        var basic_Title="盘点任务管理";
		var show_Width=1000;
		var show_Hight=500;
		var grid;
		var ctType='${ctType}';
		$(function(){
			//按钮可见性
			var zdType = '${zdType}';
			if('ckIn'==zdType){
				$("#add").hide();
				$("#del").hide();
				$("#task").hide();
			}
			if('make'==zdType){
				$("#add").hide();
				$("#del").hide();
			}
			if('task'==zdType){
				$("#task").hide();
			}
			//grid的结果
			grid = $("#table1").ligerGrid({
		        columns: [{ display: '单据编号', name: 'zd002TaskCode', width: 180 },
		                  { display: '盘点仓库', name: 'zd001WhName', width: 180},
		                  { display: '制单人', name: 'bizCreatorName', width: 150},
		                  { display: '盘点人', name: 'zd004Agent', width:150},
		                  { display: '单据状态', name: 'zd003TaskStatus', width: 150,
		                	  render: function (item){
		                		  var billStatus=item.zd003TaskStatus;
		                		  if(billStatus=="DRAFT"){
		                			  return "<span style='color:red;'>草稿</span>";
		                		  }if(billStatus=="NOSELECT"){
		                			  return "<span style='color:red;'>未盘点</span>";
		                		  }if(billStatus=="CHECK"){
		                			  return "<span style='color:red;'>盘点中</span>";
		                		  }if(billStatus=="AUDIT"){
		                			  return "<span style='color:red;'>审核中</span>";
		                		  }if(billStatus=="END"){
		                			  return "<span style='color:red;'>已完结</span>";
		                		  }if(billStatus=="RETURN"){
		                			  return "<span style='color:red;'>驳回重盘</span>";
		                		  }if(billStatus=="TOVOID"){
		                			  return "<span style='color:red;'>月末作废</span>";
		                		  };
		                  }},
		                  { display: '盘点类型', name: 'zd009BillType', width: 150,
		                	  render: function (item){
		                		  var billType=item.zd009BillType;
		                		  if(billType=="MC"){
		                			  return "月度盘点";
		                		  }else if(billType=="EC"){
		                			  return "日常盘点";
		                		  }
		                  }},
		                  { display: '盘点日期', name: 'zd008StepDate', width: 180,
		                	  render: function (item){
		                		  var cdate=new Date(item.zd008StepDate);
		                		  return formatDate(cdate,"yyyy-MM-dd");
		                	  }},
		                  { display: '创建时间', name: 'bizCreatorDate', width: 180,
		                	  render: function (item){
		                		  var cdate=new Date(item.bizCreatorDate);
		                		  return formatDate(cdate,"yyyy-MM-dd");
		                	  }}
		                  ],
		                  enabledEdit: true,
		                  usePager: true, rownumbers: true,
		                  pageSize:15,
		                  pageSizeOptions :[15,25,35],
		                  url:basic_Url+"/list.do?checkTask=${checkTask}"+"&ctType="+ctType,
		                  width: "100%", height:'100%', checkbox: true,
		                  enabledSort:false,
	                      onDblClickRow : function (data, rowindex, rowobj){
	                    		var url=basic_WUrl+"/operate/edit/"+data.id+".do?checkTask=${checkTask}"+"&ctType="+ctType;
	                    		ShowIframeDialog("operate",basic_Title,url,show_Width,show_Hight);
	                       }
		                  });
			$("#pageloading").hide();
		});
		function createSearch(){
			init(1,8,'60,120,60,100,60,100,60,100','10%');
			//第一行的数据
			addCommon(0,0,"lable","单据编号：");
			addCommon(0,1,"txtlike","zd002TaskCode");
			addCommon(0,2,"lable","盘点仓库：");
			addCommon(0,3,"selectEnum","zd001WhName","<option></option><c:forEach var="s" items="${wh}"><option value='${s.zd003Name}'>${s.zd003Name}</option></c:forEach>");
			addCommon(0,4,"lable","制单人：");
			addCommon(0,5,"txtlike","bizCreatorName");
			addCommon(0,6,"lable","单据状态");
 			addCommon(0,7,"selectEnum","zd003TaskStatus","<option></option><option value='DRAFT'>草稿</option><option value='NOSELECT'>未盘点</option>"
 					+"<option value='CHECK'>盘点中</option><option value='AUDIT'>审核中</option><option value='END'>完成</option>"
					+"<option value='RETURN'>驳回重盘</option>");
		}

		function searchAP(){
			multipleSearch("#table1",true,"",basic_Url+"/list.do?checkTask=${checkTask}"+"&ctType="+ctType);
		}
		document.onkeydown=keyListener;
		function keyListener(e){
		    e = e ? e : event;
		    if(e.keyCode == 13){
		    	searchAP();
		    }
		}
		function addpd(){
			var url = basic_WUrl+"/operate/add/0.do?checkTask=${checkTask}"+"&ctType="+ctType;

			ShowIframeDialog("operate",basic_Title,url,show_Width,show_Hight);
		}


		function checkdel(){
			var manager = $("#table1").ligerGetGridManager();
			var rows =manager.getSelectedRows();
			var bol = false;
			if (rows==null || 0 == rows.length){
					$.dialog.alert('请选择需要操作删除的行！');
					return;
			}
			for(var i=0;i<rows.length;i++){
			 	if (rows[i].bizCreatorName != "${user.name}"){
			 		bol = true;
				}
			}
			if(bol){
				$.dialog.alert('请选择自己创建的草稿单据进行删除操作!');
				return;
			}else{
				bol = false;
				for(var i=0;i<rows.length;i++){
				 	if (rows[i].zd003BillStatus!="DRAFT"||rows[i].zd003BillStatus!="RETURN"){
				 		bol = true;
					}
				}
				if(bol){
					$.dialog.alert('非草稿状态的单据不能删除!');
					return;
				}else{
					del();
					bol = false;
				}
			}
		}
		//去盘点
		function task(){
			var arr="";
			var manager = $("#table1").ligerGetGridManager();
			var rows =manager.getSelectedRows();
/* 			if(rows==null||rows.length==0){
				$.dialog.alert('请选择需要操作去盘点的行记录！');
				return;
			} */
			for(var i=0;i<rows.length;i++){
				if(arr==""){
		 			arr=rows[i].id;
		 		}else{
		 			arr=arr+","+rows[i].id;
		 		}
			}
			var url=basic_WUrl+"/checkTask.do?taskIdStr="+arr+"&ctType="+ctType;
			grid.deleteSelectedRow();
			ShowIframeDialogMax("operate","盘点任务单",url,show_Width,show_Hight);

		}
	</script>

  </head>
 <body style="padding:10px" onload="createSearch()">
       <div id="layout1">
          <div class="panelBar">
	            <ul class="toolBar">
		           <li><a class="add" onclick="addpd()" id="add"><span>新增</span></a></li>
				   <li><a class="delete" onclick="checkdel()" id="del"><span>删除</span></a></li>
				   <li><a class="add" onclick="task()" id="task"><span>去盘点</span></a></li>
               </ul>
          </div>
          <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >
                        <tbody id="newbody">
                        </tbody>
 	                </table>
                    <div class="subBar">
			             <ul>
				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="searchAP()">查询</button></div></div></li>
				             <li><a class="button" onclick="clearSearch()"><span>重置</span></a></li>
			             </ul>
	                </div>
               </div>
          </div>
      </div>
      <div position="center" id="table1">
      </div>
      <div class="clear"></div>
    </body>
</html>
